﻿<UserControl x:Class="ScrumSprintMonitor.UI.Wpf.Views.MonitorWindow.SprintProgress"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="progress" MinHeight="21">

    <UserControl.Resources>
        <Style x:Key="SliderButtonStyle" TargetType="{x:Type RepeatButton}">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="IsTabStop" Value="false"/>
            <Setter Property="Focusable" Value="false"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                        <Border Background="Transparent"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="SliderThumbStyle" TargetType="{x:Type Thumb}">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Height" Value="14"/>
            <Setter Property="Width" Value="14"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Ellipse
                         Name="Ellipse"
                         Fill="Yellow"
                         Stroke="#800000FF"
                         StrokeThickness="1"/>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Ellipse" Property="Fill" Value="#808080"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter TargetName="Ellipse" Property="Fill" Value="#EEEEEE"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
            
        <ControlTemplate x:Key="HorizontalSlider" TargetType="{x:Type Slider}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TickBar
                   Name="TopTick"
                   Height="4"
                   Fill="#404040"
                   Placement="Top"
                   SnapsToDevicePixels="True"
                   Visibility="Collapsed"/>
                <Border
                   Name="TrackBackground"
                   Height="4"
                   Grid.Row="1"
                   BorderBrush="#20404040"
                   BorderThickness="1"
                   CornerRadius="2">
                    <Border.Background>
                        <LinearGradientBrush>
                            <GradientBrush.GradientStops>
                                <GradientStop Offset="0" Color="#FF5F7143"/>
                                <GradientStop Offset="{Binding Position, ElementName=progress}" Color="#FFB8C0AC"/>
                                <GradientStop Offset="{Binding Position, ElementName=progress}" Color="#FFFBB7B5"/>
                                <GradientStop Offset="1" Color="#FF702828"/>
                            </GradientBrush.GradientStops>
                        </LinearGradientBrush>
                    </Border.Background>
                </Border>
                <Track Name="PART_Track" Grid.Row="1">
                    <Track.DecreaseRepeatButton>
                        <RepeatButton Command="Slider.DecreaseLarge" Style="{StaticResource SliderButtonStyle}"/>
                    </Track.DecreaseRepeatButton>
                    <Track.Thumb>
                        <Thumb Style="{StaticResource SliderThumbStyle}"/>
                    </Track.Thumb>
                    <Track.IncreaseRepeatButton>
                        <RepeatButton Command="Slider.IncreaseLarge" Style="{StaticResource SliderButtonStyle}"/>
                    </Track.IncreaseRepeatButton>
                </Track>
                <TickBar
                   Name="BottomTick"
                   Height="4"
                   Grid.Row="2"
                   Fill="{TemplateBinding Foreground}"
                   Placement="Bottom"
                   SnapsToDevicePixels="True"
                   Visibility="Collapsed"/>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="TickPlacement" Value="TopLeft">
                    <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
                </Trigger>
                <Trigger Property="TickPlacement" Value="BottomRight">
                    <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
                </Trigger>
                <Trigger Property="TickPlacement" Value="Both">
                    <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <ControlTemplate x:Key="VerticalSlider" TargetType="{x:Type Slider}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition MinWidth="{TemplateBinding Slider.MinWidth}" Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TickBar
                   Name="TopTick"
                   Width="4"
                   Fill="#404040"
                   Placement="Left"
                   SnapsToDevicePixels="True"
                   Visibility="Collapsed"/>
                <Border
                   Name="TrackBackground"
                   Width="4"
                   Grid.Column="1"
                   BorderBrush="#20404040"
                   BorderThickness="1"
                   CornerRadius="2">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0,0" StartPoint="1,1">
                            <GradientBrush.GradientStops>
                                <GradientStop Offset="0" Color="#FF5F7143"/>
                                <GradientStop Offset="{Binding Position, ElementName=progress}" Color="#FFB8C0AC"/>
                                <GradientStop Offset="{Binding Position, ElementName=progress}" Color="#FFFBB7B5"/>
                                <GradientStop Offset="1" Color="#FF702828"/>
                            </GradientBrush.GradientStops>
                        </LinearGradientBrush>
                    </Border.Background>
                </Border>
                <Track Name="PART_Track" Grid.Column="1">
                    <Track.DecreaseRepeatButton>
                        <RepeatButton Command="Slider.DecreaseLarge" Style="{StaticResource SliderButtonStyle}"/>
                    </Track.DecreaseRepeatButton>
                    <Track.Thumb>
                        <Thumb Style="{StaticResource SliderThumbStyle}"/>
                    </Track.Thumb>
                    <Track.IncreaseRepeatButton>
                        <RepeatButton Command="Slider.IncreaseLarge" Style="{StaticResource SliderButtonStyle}"/>
                    </Track.IncreaseRepeatButton>
                </Track>
                <TickBar
                   Name="BottomTick"
                   Width="4"
                   Grid.Column="2"
                   Fill="{TemplateBinding Foreground}"
                   Placement="Right"
                   SnapsToDevicePixels="True"
                   Visibility="Collapsed"/>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="TickPlacement" Value="TopLeft">
                    <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
                </Trigger>
                <Trigger Property="TickPlacement" Value="BottomRight">
                    <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
                </Trigger>
                <Trigger Property="TickPlacement" Value="Both">
                    <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <Style TargetType="{x:Type Slider}">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Style.Triggers>
                <Trigger Property="Orientation" Value="Horizontal">
                    <Setter Property="MinWidth" Value="104"/>
                    <Setter Property="MinHeight" Value="21"/>
                    <Setter Property="Template" Value="{StaticResource HorizontalSlider}"/>
                </Trigger>
                <Trigger Property="Orientation" Value="Vertical">
                    <Setter Property="MinWidth" Value="21"/>
                    <Setter Property="MinHeight" Value="104"/>
                    <Setter Property="Template" Value="{StaticResource VerticalSlider}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    
    <Slider Orientation="{Binding Orientation, ElementName=progress}" Value="{Binding Position, ElementName=progress}" Maximum="1" TickFrequency="0.25" TickPlacement="None" Focusable="False" IsHitTestVisible="False" />
</UserControl>
